﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hospital.Common;
using Hospital.BLL.IBLL;

namespace Hospital.Web
{
    public partial class ManageAnnouncement : System.Web.UI.Page
    {
        #region Member
        private IAnnouncementService announcementService;
        #endregion

        #region Property
        public IAnnouncementService AnnouncementService
        {
            set { announcementService = value; }
            get { return announcementService; }
        }
        #endregion

        #region Load
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadAllAnnounce();
            }
        }
        #endregion

        #region Event
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvAnnouncement_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Guid AnnounceId = ConvertHelper.GetGuid(this.gvAnnouncement.DataKeys[e.RowIndex].Value);
            if (announcementService.DeleteAnnouncementById(AnnounceId))
                LoadAllAnnounce();
        }

        /// <summary>
        /// 编辑记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvAnnouncement_RowEditing(object sender, GridViewEditEventArgs e)
        {
            Guid AnnounceId = ConvertHelper.GetGuid(this.gvAnnouncement.DataKeys[e.NewEditIndex].Value);
            this.Response.Redirect(string.Format("EditAnnouncement.aspx?Id={0}", AnnounceId));
        }
        /// <summary>
        /// 查看详情
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvAnnouncement_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("ReviewDetail"))
            {
                Guid AnnounceId = ConvertHelper.GetGuid(e.CommandArgument);
                this.Response.Redirect(string.Format("AnnouncementDetail.aspx?Id={0}", AnnounceId), false);
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvAnnouncement_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.gvAnnouncement.PageIndex = e.NewPageIndex;
            LoadAllAnnounce();
        }
        #endregion

        #region Function
        private void LoadAllAnnounce()
        {
            IList<Hospital.Model.Announcement> announceList = announcementService.GetAnnouncement(10);
            this.gvAnnouncement.DataSource = announceList;
            this.gvAnnouncement.DataBind();
        }

        private void LoadAllAnnounceById(Guid Id)
        {
            //IList<Hospital.Model.Announcement> announceList = announcementService.GetAnnouncement();
        }
        #endregion


    }
}
